package com.laolei.template.test;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;
import org.thymeleaf.context.Context;
import org.thymeleaf.context.IContext;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;

import com.laolei.template.assist.BuildData;
import com.laolei.template.assist.OutData;

@Component
public class ThymeleafTemplateBuild implements CommandLineRunner{
	@Autowired ThymeleafViewResolver thymeleafViewResolver;
	@Autowired SpringTemplateEngine thymeleafTemplateEngine;

	@Override
	public void run(String... args) throws Exception {
		this.test();
		this.testResolver();
	}
	
	private void test() {
        String templateName="abc";
		IContext context=new Context(Locale.US, BuildData.build());
		String result =thymeleafTemplateEngine.process(templateName, context);
		System.err.println(result);  
	}
	
	private void testResolver() throws Exception {
		View view = thymeleafViewResolver.resolveViewName("abc", Locale.US);
		OutData.out(view);
	}
}
